package com.evil.common.account.util;

import com.evil.common.account.constant.AccountRedisConstant;
import com.evil.common.redis.util.RedisKeyUtil;
import com.evil.common.core.util.StreamUtil;

import java.util.Collection;
import java.util.Map;

/**
 * @author liyang
 * @date 2022-08-08 00:00
 */
public class AccountRedisKeyUtil extends RedisKeyUtil {

    // region 用户

    /**
     * 会话资源-用户
     *
     * @return String
     */
    public static String requestUuidUserKey(Long userId) {
        String requestUuid = RedisKeyUtil.requestUuid();
        return RedisKeyUtil.requestUuidKey(requestUuid) + ":" + AccountRedisConstant.REQUEST_UUID_USER_PREFIX + userId;
    }

    /**
     * 会话资源-用户
     *
     * @return Map
     */
    public static Map<Long, String> requestUuidUserKeyMap(Collection<Long> userIds) {
        return StreamUtil.toMapKV(userIds, e -> e, AccountRedisKeyUtil::requestUuidUserKey);
    }

    /**
     * 会话资源-用户基础信息
     *
     * @return String
     */
    public static String requestUuidUserBaseKey(Long userId) {
        String requestUuid = RedisKeyUtil.requestUuid();
        return RedisKeyUtil.requestUuidKey(requestUuid) + ":" + AccountRedisConstant.REQUEST_UUID_USER_BASE_PREFIX + userId;
    }

    /**
     * 会话资源-用户基础信息
     *
     * @return Map
     */
    public static Map<Long, String> requestUuidUserBaseKeyMap(Collection<Long> userIds) {
        return StreamUtil.toMapKV(userIds, e -> e, AccountRedisKeyUtil::requestUuidUserKey);
    }
    // endregion

    // region 部门

    /**
     * 会话资源-部门
     *
     * @return String
     */
    public static String requestUuidDepartmentKey(Long departmentId) {
        String requestUuid = RedisKeyUtil.requestUuid();
        return RedisKeyUtil.requestUuidKey(requestUuid) + ":" + AccountRedisConstant.REQUEST_UUID_DEPARTMENT_PREFIX + departmentId;
    }

    /**
     * 会话资源-部门
     *
     * @return Map
     */
    public static Map<Long, String> requestUuidDepartmentKeyMap(Collection<Long> departmentIds) {
        return StreamUtil.toMapKV(departmentIds, e -> e, AccountRedisKeyUtil::requestUuidDepartmentKey);
    }

    /**
     * 会话资源-部门基础信息
     *
     * @return String
     */
    public static String requestUuidDepartmentBaseKey(Long departmentId) {
        String requestUuid = RedisKeyUtil.requestUuid();
        return RedisKeyUtil.requestUuidKey(requestUuid) + ":" + AccountRedisConstant.REQUEST_UUID_DEPARTMENT_BASE_PREFIX + departmentId;
    }

    /**
     * 会话资源-部门基础信息
     *
     * @return Map
     */
    public static Map<Long, String> requestUuidDepartmentBaseKeyMap(Collection<Long> departmentIds) {
        return StreamUtil.toMapKV(departmentIds, e -> e, AccountRedisKeyUtil::requestUuidDepartmentBaseKey);
    }
    // endregion

    // region 角色

    /**
     * 会话资源-角色
     *
     * @return String
     */
    public static String requestUuidRoleKey(Long roleId) {
        String requestUuid = RedisKeyUtil.requestUuid();
        return RedisKeyUtil.requestUuidKey(requestUuid) + ":" + AccountRedisConstant.REQUEST_UUID_ROLE_PREFIX + roleId;
    }

    /**
     * 会话资源-角色
     *
     * @return Map
     */
    public static Map<Long, String> requestUuidRoleKeyMap(Collection<Long> roleIds) {
        return StreamUtil.toMapKV(roleIds, e -> e, AccountRedisKeyUtil::requestUuidDepartmentKey);
    }

    /**
     * 会话资源-角色基础信息
     *
     * @return String
     */
    public static String requestUuidRoleBaseKey(Long roleId) {
        String requestUuid = RedisKeyUtil.requestUuid();
        return RedisKeyUtil.requestUuidKey(requestUuid) + ":" + AccountRedisConstant.REQUEST_UUID_ROLE_BASE_PREFIX + roleId;
    }

    /**
     * 会话资源-角色基础信息
     *
     * @return Map
     */
    public static Map<Long, String> requestUuidRoleBaseKeyMap(Collection<Long> roleIds) {
        return StreamUtil.toMapKV(roleIds, e -> e, AccountRedisKeyUtil::requestUuidDepartmentBaseKey);
    }
    // endregion

    // region 企业

    /**
     * 会话资源-企业
     *
     * @return String
     */
    public static String requestUuidEnterpriseKey(Long enterpriseId) {
        String requestUuid = RedisKeyUtil.requestUuid();
        return RedisKeyUtil.requestUuidKey(requestUuid) + ":" + AccountRedisConstant.REQUEST_UUID_ENTERPRISE_PREFIX + enterpriseId;
    }

    /**
     * 会话资源-企业
     *
     * @return Map
     */
    public static Map<Long, String> requestUuidEnterpriseKeyMap(Collection<Long> enterpriseIds) {
        return StreamUtil.toMapKV(enterpriseIds, e -> e, AccountRedisKeyUtil::requestUuidDepartmentKey);
    }

    /**
     * 会话资源-企业基础信息
     *
     * @return String
     */
    public static String requestUuidEnterpriseBaseKey(Long enterpriseId) {
        String requestUuid = RedisKeyUtil.requestUuid();
        return RedisKeyUtil.requestUuidKey(requestUuid) + ":" + AccountRedisConstant.REQUEST_UUID_ENTERPRISE_BASE_PREFIX + enterpriseId;
    }

    /**
     * 会话资源-企业基础信息
     *
     * @return Map
     */
    public static Map<Long, String> requestUuidEnterpriseBaseKeyMap(Collection<Long> enterpriseIds) {
        return StreamUtil.toMapKV(enterpriseIds, e -> e, AccountRedisKeyUtil::requestUuidDepartmentBaseKey);
    }
    // endregion
}
